package cn.car91.http;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.content.Context;
import cn.car91.bean.AreaParam;
import cn.car91.config.InitApplication;
import cn.car91.utils.DesUtils;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseStream;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.util.LogUtils;
import com.thinkland.sdk.android.DataCallBack;
import com.thinkland.sdk.android.JuheData;
import com.thinkland.sdk.android.Parameters;

/**
 * 文件 cn.car91.http.Car91HttpUtil.java 主要负责网络通讯，提交请求
 *
 * @author 周海刚 时间 2014年11月20日
 */
public class Car91HttpUtil {
	private Context mContext;
	private InitApplication initApplication;

	public Car91HttpUtil(Context context) {
		this.mContext = context;
		initApplication = (InitApplication) mContext.getApplicationContext();
	}

	HttpHandler handler = null;

	HttpUtils http = new HttpUtils(1000 * 10);

	public void initAppConfig(RequestCallBack callBack) {
		AsyncHttp(initApplication.getAndroidServerUrl() + "/app_config.xml",
				new RequestParams(), callBack, HttpMethod.POST);
	}

	public void pushLog(String log) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "save");
		params.addBodyParameter("log", log);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/log.action",
				params, null, HttpMethod.POST);
	}

	public void getUserBasic(String uid, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "detail");
		params.addBodyParameter("uid", uid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/user.action",
				params, callBack, HttpMethod.POST);
	}

	public void getUserDetail(String uid, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "basic");
		params.addBodyParameter("uid", uid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/user.action",
				params, callBack, HttpMethod.POST);
	}

	public void loginUser(String name, String password, RequestCallBack callBack)
			throws Exception {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "login");
		param.addBodyParameter("uname", name);

		DesUtils desUtil = new DesUtils(initApplication.getEncryptCode());
		param.addBodyParameter("pwd", desUtil.encrypt(password));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/user.action",
				param, callBack, HttpMethod.POST);
	}

	public void checkUserAccountName(String name, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("param", name);
		AsyncHttp(initApplication.getCenterServerUrl() + "/user/checkNick",
				params, callBack, HttpMethod.POST);
	}

	public void checkUserAccountCode(String code, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("param", code);
		AsyncHttp(initApplication.getCenterServerUrl() + "/user/checkCode",
				params, callBack, HttpMethod.POST);
	}

	public void sendAccountCode(String mobile, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("mobile", mobile);
		AsyncHttp(initApplication.getCenterServerUrl() + "/user/sendCheckCode",
				params, callBack, HttpMethod.POST);
	}

	public void sendForgetCode(String mobile, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("mobile", mobile);
		AsyncHttp(initApplication.getCenterServerUrl()
				+ "/user/sendForgotCheckCode", params, callBack,
				HttpMethod.POST);
	}

	public void retrieveAccount(String mobile, String mobileCode, String pwd,
			String repwd, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("password", pwd);
		params.addBodyParameter("repassword", repwd);
		params.addBodyParameter("mcode", mobileCode);
		params.addBodyParameter("mobile", mobile);
		params.addBodyParameter("ismobile", "true");
		AsyncHttp(initApplication.getCenterServerUrl()
				+ "/user/mobilenowforgot", params, callBack, HttpMethod.POST);
	}

	public void getCurApkVersion(RequestCallBack callBack) {
		AsyncHttp(initApplication.getAndroidServerUrl() + "/app_ver.xml", null,
				callBack, HttpMethod.POST);
	}

	public void downUpdateApk(String savePath, RequestCallBack callBack)
			throws IOException {
		HttpDown(initApplication.getAndroidServerUrl() + "/car91.apk",
				savePath, null, callBack);
	}

	public void registUser(String nick, String pwd, String repwd,
			String mobile, String mobileCode, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("nick", nick);
		params.addBodyParameter("password", pwd);
		params.addBodyParameter("repassword", repwd);
		params.addBodyParameter("mcode", mobileCode);
		params.addBodyParameter("mobile", mobile);
		params.addBodyParameter("ismobile", "true");
		AsyncHttp(initApplication.getCenterServerUrl() + "/user/nowregist",
				params, callBack, HttpMethod.POST);
	}

	public void getPublicWashShop(int page, String orderby, String rgrade,
			AreaParam areaParam, RequestCallBack callBack) {
		RequestParams param = new RequestParams("utf-8");
		param.addBodyParameter("method", "list");
		param.addBodyParameter(areaParam.paramName, areaParam.paramValue);
		param.addBodyParameter("order", orderby);
		param.addBodyParameter("p", String.valueOf(page));
		param.addBodyParameter("sids","8");
		param.addBodyParameter("rgrade", rgrade);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void getSearchWashShop(int page, String key, RequestCallBack callBack) {
		RequestParams param = new RequestParams("utf-8");
		param.addBodyParameter("k", key);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getCenterServerUrl() + "/washshop/search",
				param, callBack, HttpMethod.POST);
	}

	public void getWashShopDetail(String wid, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "detail");
		param.addBodyParameter("wid", wid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/washshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void getUserWashShop(int page, String uid, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "washshop");
		param.addBodyParameter("uid", uid);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/collection.action",
				param, callBack, HttpMethod.POST);
	}

	public void getWashShopComments(int page, String wid, String score,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "list");
		param.addBodyParameter("id", wid);
		param.addBodyParameter("type", "washshop");
		param.addBodyParameter("s", score);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				param, callBack, HttpMethod.POST);
	}

	public void addWashShopComment(String wid, String uid, String content,
			float attitude, float charge, float technology, float hardware,
			float environment, String good, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "add");
		params.addBodyParameter("type", "washshop");
		params.addBodyParameter("id", wid);
		params.addBodyParameter("uid", uid);
		params.addBodyParameter("content", content);
		params.addBodyParameter("a", String.valueOf(attitude));
		params.addBodyParameter("c", String.valueOf(charge));
		params.addBodyParameter("t", String.valueOf(technology));
		params.addBodyParameter("h", String.valueOf(hardware));
		params.addBodyParameter("e", String.valueOf(environment));
		params.addBodyParameter("g", good);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				params, callBack, HttpMethod.POST);
	}

	public void washShopCollect(String wid, String uid, String method,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "collect");
		param.addBodyParameter("wid", wid);
		param.addBodyParameter("uid", uid);
		param.addBodyParameter("way", method);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/washshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void checkWashShopCollect(String wid, String uid,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "checkcollection");
		param.addBodyParameter("wid", wid);
		param.addBodyParameter("uid", uid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/washshop.action",
				param, callBack, HttpMethod.POST);
	}

	// 到这里了
	public void getPublicRepairShop(int page, String orderby, 
	        String rgrade, AreaParam areaParam, 
	        RequestCallBack callBack) {
		RequestParams param = new RequestParams("utf-8");
		param.addBodyParameter("method", "list");
		param.addBodyParameter(areaParam.paramName, areaParam.paramValue);
		param.addBodyParameter("rgrade", rgrade);
		param.addBodyParameter("order", orderby);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void getSearchRepairShop(int page, String key,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams("utf-8");
		param.addBodyParameter("k", key);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getCenterServerUrl() + "/repairshop/search",
				param, callBack, HttpMethod.POST);
	}

	public void getRepairShopDetail(String rid, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "detail");
		param.addBodyParameter("rid", rid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void getUserRepairShop(int page, String uid, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "repairshop");
		param.addBodyParameter("uid", uid);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/collection.action",
				param, callBack, HttpMethod.POST);
	}

	public void getRepairShopComments(int page, String rid, String score,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "list");
		param.addBodyParameter("id", rid);
		param.addBodyParameter("type", "repairshop");
		param.addBodyParameter("s", score);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				param, callBack, HttpMethod.POST);
	}
	
	public void getRepairShopCommentItem(String rid, String pitem,
      RequestCallBack callBack) {
    RequestParams param = new RequestParams();
    param.addBodyParameter("rid", rid);
    param.addBodyParameter("pitem", pitem);
    AsyncHttp(initApplication.getRepairShopServerUrl()+ "/comment/getcommentitemscore",
        param, callBack, HttpMethod.POST);
  }

	public void addRepairShopComment(String rid, String uid, String content,
			float attitude, float charge, float technology, float hardware,
			float environment, String good, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "add");
		params.addBodyParameter("type", "repairshop");
		params.addBodyParameter("id", rid);
		params.addBodyParameter("uid", uid);

		params.addBodyParameter("content", content);
		params.addBodyParameter("a", String.valueOf(attitude));
		params.addBodyParameter("c", String.valueOf(charge));
		params.addBodyParameter("t", String.valueOf(technology));
		params.addBodyParameter("h", String.valueOf(hardware));
		params.addBodyParameter("e", String.valueOf(environment));
		params.addBodyParameter("g", good);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				params, callBack, HttpMethod.POST);
	}

	public void repairShopCollect(String rid, String uid, String method,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "collect");
		param.addBodyParameter("rid", rid);
		param.addBodyParameter("uid", uid);
		param.addBodyParameter("way", method);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void checkRepairShopCollect(String rid, String uid,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "checkcollection");
		param.addBodyParameter("rid", rid);
		param.addBodyParameter("uid", uid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void getPublicArticle(int page, int atid, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "list");
		params.addBodyParameter("atid", String.valueOf(atid));
		params.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/article.action",
				params, callBack, HttpMethod.POST);
	}

	public void getSearchArticle(int page, String key, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("infos", key);
		params.addBodyParameter("p", String.valueOf(page));
		params.addBodyParameter("ismobile", "true");
		AsyncHttp(initApplication.getArticleServerUrl() + "/article/search",
				params, callBack, HttpMethod.POST);
	}

	public void getArticleDetail(String aid, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "detail");
		param.addBodyParameter("aid", aid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/article.action",
				param, callBack, HttpMethod.POST);
	}

	public void getArticleSorts(RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "allsort");
		AsyncHttp(initApplication.getAndroidServerUrl() + "/article.action",
				params, callBack, HttpMethod.POST);
	}

	public void getArticleComments(int page, String aid,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "list");
		params.addBodyParameter("type", "article");
		params.addBodyParameter("id", aid);
		params.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				params, callBack, HttpMethod.POST);
	}

	public void addArticleComment(String aid, String uid, String content,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "add");
		params.addBodyParameter("type", "article");
		params.addBodyParameter("id", aid);
		params.addBodyParameter("uid", uid);
		params.addBodyParameter("content", content);
		;
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				params, callBack, HttpMethod.POST);
	}

	public void getAroundRepairShop(int page, double lat, double lon,
			double latd, double lond, String sids, String orderby, String rgrade, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "nearby");
		params.addBodyParameter("lat", String.valueOf(lat));
		params.addBodyParameter("lon", String.valueOf(lon));
		params.addBodyParameter("latd", String.valueOf(latd));
		params.addBodyParameter("lond", String.valueOf(lond));
		params.addBodyParameter("p", String.valueOf(page));
		params.addBodyParameter("rgrade", rgrade);
		params.addBodyParameter("order", orderby);
		params.addBodyParameter("sids", sids);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/around.action",
				params, callBack, HttpMethod.POST);
	}

	public void getPublicExposure(int page, RequestCallBack callBack) {
		RequestParams param = new RequestParams("utf-8");
		param.addBodyParameter("method", "list");
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/exposure.action",
				param, callBack, HttpMethod.POST);
	}

	public void getSearchExposure(int page, String key, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("infos", key);
		params.addBodyParameter("p", String.valueOf(page));
		params.addBodyParameter("ismobile", "true");
		AsyncHttp(initApplication.getExposureServerUrl() + "/exposure/search",
				params, callBack, HttpMethod.POST);
	}

	public void getExposureDetail(String eid, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "detail");
		param.addBodyParameter("eid", eid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/exposure.action",
				param, callBack, HttpMethod.POST);
	}

	public void getExposureComments(int page, String eid,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "list");
		params.addBodyParameter("type", "exposure");
		params.addBodyParameter("id", eid);
		params.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				params, callBack, HttpMethod.POST);
	}

	public void addExposureComment(String eid, String uid, String content,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "add");
		params.addBodyParameter("type", "exposure");
		params.addBodyParameter("id", eid);
		params.addBodyParameter("uid", uid);
		params.addBodyParameter("content", content);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				params, callBack, HttpMethod.POST);
	}

	public void getExposureRepairShop(String rid, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "exposure");
		params.addBodyParameter("rid", rid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				params, callBack, HttpMethod.POST);
	}

	public void getUserExposureDetail(String uid, String eid, String state,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "userexposuredetail");
		params.addBodyParameter("eid", eid);
		params.addBodyParameter("state", state);
		params.addBodyParameter("uid", uid);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/exposure.action",
				params, callBack, HttpMethod.POST);
	}

	public void getUserExposure(int page, String uid, String state,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "userexposure");
		params.addBodyParameter("uid", uid);
		params.addBodyParameter("state", String.valueOf(state));
		params.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/exposure.action",
				params, callBack, HttpMethod.POST);
	}

	public void addExposure(String uid, String rid, String name, int cid,
			int did, String address, String phone, String title, String reason,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "add");
		params.addBodyParameter("u", uid);
		params.addBodyParameter("rid", rid);
		params.addBodyParameter("n", name);
		params.addBodyParameter("c", String.valueOf(cid));
		params.addBodyParameter("d", String.valueOf(did));
		params.addBodyParameter("a", address);
		params.addBodyParameter("p", phone);
		params.addBodyParameter("t", title);
		params.addBodyParameter("r", reason);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/exposure.action",
				params, callBack, HttpMethod.POST);
	}

	public void getUserComment(int page, String uid, String type,
			RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "usercomment");
		param.addBodyParameter("uid", uid);
		param.addBodyParameter("type", type);
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/comment.action",
				param, callBack, HttpMethod.POST);
	}

	public void getAllProvinces(RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "provinces");
		AsyncHttp(initApplication.getAndroidServerUrl() + "/place.action",
				params, callBack, HttpMethod.POST);
	}

	public void getAllCities(RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "allcities");
		AsyncHttp(initApplication.getAndroidServerUrl() + "/place.action",
				params, callBack, HttpMethod.POST);
	}

	public void getProvinceCities(int provinceId, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "cities");
		params.addBodyParameter("pid", String.valueOf(provinceId));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/place.action",
				params, callBack, HttpMethod.POST);
	}

	public void getCityDistricts(int cityId, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "districts");
		params.addBodyParameter("cid", String.valueOf(cityId));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/place.action",
				params, callBack, HttpMethod.POST);
	}

	public void getDistrictStreets(int districtId, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("method", "streets");
		params.addBodyParameter("did", String.valueOf(districtId));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/place.action",
				params, callBack, HttpMethod.POST);
	}

	public void getWeather(String cityName, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "index");
		params.addBodyParameter("city", cityName);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/weather.action",
				params, callBack, HttpMethod.POST);
	}

	public void getOil(String cityName, RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "index");
		params.addBodyParameter("city", cityName);
		AsyncHttp(initApplication.getAndroidServerUrl() + "/oil.action",
				params, callBack, HttpMethod.POST);
	}

	public void getAPIWeather(String cityName, DataCallBack callBack)
			throws UnsupportedEncodingException {
		Parameters params = new Parameters();
		params.add("cityname", URLEncoder.encode(cityName.trim(), "UTF-8"));
		JuheData.executeWithAPI(initApplication.apiWeatherId,
				"http://op.juhe.cn/onebox/weather/query", JuheData.GET, params,
				callBack);
	}

	public void saveAPIWeather(String cityName, String result,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "save");
		params.addBodyParameter("city", cityName);
		params.addBodyParameter("json", result.replace("null", "\"\""));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/weather.action",
				params, callBack, HttpMethod.POST);
	}

	public void saveAPIOil(String cityName, String result,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "save");
		params.addBodyParameter("city", cityName);
		params.addBodyParameter("json", result.replace("null", "\"\""));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/oil.action",
				params, callBack, HttpMethod.POST);
	}

	public void getSpread(int page, RequestCallBack callBack) {
		RequestParams param = new RequestParams();
		param.addBodyParameter("method", "spread");
		param.addBodyParameter("p", String.valueOf(page));
		AsyncHttp(initApplication.getAndroidServerUrl() + "/repairshop.action",
				param, callBack, HttpMethod.POST);
	}

	public void addSuggest(String suggest, String uid, String uname,
			RequestCallBack callBack) {
		RequestParams params = new RequestParams("utf-8");
		params.addBodyParameter("method", "add");
		params.addBodyParameter("content", suggest);
		if (uid != null) {
			params.addBodyParameter("uid", uid);
			params.addBodyParameter("uname", uname);
		}
		AsyncHttp(initApplication.getAndroidServerUrl() + "/suggest.action",
				params, callBack, HttpMethod.POST);
	}

	public void getGoodsInfo(String url, RequestCallBack callBack) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("ean", url);
		AsyncHttp("http://www.liantu.com/tiaoma/query.php", params, callBack,
				HttpMethod.POST);
	}
	
	public void getNewsInfo(String page, RequestCallBack callBack) {
        RequestParams params = new RequestParams();
        params.addBodyParameter("ismobile", "true");
        params.addBodyParameter("p", String.valueOf(page));
        AsyncHttp(initApplication.getArticleServerUrl() + "/news",
                params, callBack, HttpMethod.POST);
    }

	/**
	 * 异步通讯
	 *
	 * @param url
	 * @param params
	 *            参数
	 * @param callBack
	 *            回调方法
	 * @param method
	 *            传输方式
	 */
	public HttpHandler AsyncHttp(String url, RequestParams params,
			RequestCallBack callBack, HttpMethod method) {
		// 如果之前的线程没有完成
		/*
		 * if(handler!=null && handler.getState()!=State.FAILURE &&
		 * handler.getState()!=State.SUCCESS &&
		 * handler.getState()!=State.CANCELLED){ //关闭handler后
		 * onStart()和onLoading()还是会执行 handler.cancel(); }
		 */

		http.configRequestRetryCount(1);
		http.configResponseTextCharset("utf-8");
		// 设置当前请求的缓存时间
		http.configCurrentHttpCacheExpiry(0 * 1000);
		// 设置默认请求的缓存时间
		http.configDefaultHttpCacheExpiry(0);
		// 设置线程数
		http.configRequestThreadPoolSize(10);

		handler = http.send(method, url, params, callBack);
		return handler;
	}

	/**
	 * 同步通讯
	 *
	 * @param url
	 * @param params
	 *            参数
	 * @param method
	 *            传输方式
	 * @throws IOException
	 */
	private String TASyncHttp(String url, RequestParams params,
			HttpMethod method) throws IOException {
		try {
			return TASyncHttpStream(url, params, method).readString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtils.e(e.toString());
			return null;
		}
	}

	/**
	 * 同步通讯
	 *
	 * @param url
	 * @param params
	 *            参数
	 * @param method
	 *            传输方式
	 * @throws IOException
	 */
	private ResponseStream TASyncHttpStream(String url, RequestParams params,
			HttpMethod method) throws IOException {
		try {
			http.configRequestRetryCount(3);
			http.configResponseTextCharset("utf-8");
			return http.sendSync(method, url, params);
		} catch (HttpException e) {
			// TODO Auto-generated catch block
			LogUtils.e(e.toString());
			return null;
		}
	}

	/**
	 * 文件下载
	 *
	 * @param url
	 *            文件路径，包括文件名
	 * @param savePath
	 *            本地存储路径，包括文件名
	 * @param params
	 *            参数
	 * @param callBack
	 *            回调方法
	 * @return
	 * @throws IOException
	 */
	private HttpHandler HttpDown(String url, String savePath,
			RequestParams params, RequestCallBack callBack) throws IOException {
		http.configRequestRetryCount(3);
		http.configResponseTextCharset("utf-8");
		return http.download(url, savePath, false, // 如果目标文件存在，接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
				true, // 如果从请求返回信息中获取到文件名，下载完成后自动重命名。
				callBack);
	}
}
